<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/15
 * Time: 22:10
 */

namespace App\Library\form_builder\src\components;


class Select extends BaseForm
{
    protected $options='';
    public function set_options($data){
        $html='';
        if(empty($data)){
           return $this;
        }
        foreach($data as $key=>$value){
            $html.="<option value={$value['id']}>{$value['name']}</option>";
        }
        $this->options=$html;
        return $this;
    }
    /**
     * 生成组件
     *
     * @return array
     */
    public function build()
    {
        return [
            'field' => $this->field,
            'title' => $this->title,
            'value' => $this->values,
            'props' => $this->props,
            'validate' => $this->valids,
            'options'=>$this->options,
        ];
    }
}